home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_mac.hqx / SRGP port to 5.0 (compressed) / SRGP_SPHIGS Root / MacSPHIGS / sph_element.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-13  |  5.6 KB  |  338 lines

  1. #include "HEADERS.h"
  2. #include "sphigslocal.h"
  3. #include <string.h>
  4.  
  5.  
  6. element *baby;
  7.  
  8. #define MAKE_BABY_ELEMENT   baby = (element*) malloc ((size_t)sizeof(element))
  9. #define INSERT_BABY        SPH__insertElement (baby)
  10.  
  11. #include "sph_element.proto.h"
  12. static char *MAKE_COPY_OF_STRING(char *);
  13. static void StorePointList(element *, int, point *);
  14. static void SimpleElement(int, int);
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. /*!*/
  23. static
  24. char *MAKE_COPY_OF_STRING (char *str)
  25. {
  26.    char *copy;
  27.  
  28.    copy = (char*) malloc (strlen(str)+1);
  29.    strcpy(copy,str);
  30.    return copy;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. /*!*/
  37. void
  38. SPH_setModelingTransformation (matrix mat, int method)
  39. {
  40.    SPH_check_system_state;
  41.    SPH_check_open_structure;
  42.    SPH_check_modxform_method;
  43.  
  44.    MAKE_BABY_ELEMENT;
  45.    baby->type = ELTYP__SET_MODXFORM;
  46.    baby->info.update_type = method;
  47.    MAT3copy (baby->data.matrix, mat);
  48.    INSERT_BABY;
  49. }
  50.  
  51.  
  52. /*!*/
  53. void
  54. SPH_clearModelingTransformation (void)
  55. {
  56.    SPH_check_system_state;
  57.    SPH_check_open_structure;
  58.  
  59.    MAKE_BABY_ELEMENT;
  60.    baby->type = ELTYP__CLEAR_MODXFORM;
  61.    INSERT_BABY;
  62. }
  63.  
  64.  
  65.  
  66.  
  67. /*!*/
  68. /* not called directly by the application, called by SPH_polyhedron */
  69. void
  70. SPH__add_polyhedron_element (POLYHEDRON *newpoly)
  71. {
  72.    register i;
  73.  
  74.    MAKE_BABY_ELEMENT;
  75.    baby->type = ELTYP__POLYHEDRON;
  76.    baby->data.poly = newpoly;
  77.  
  78.    INSERT_BABY;
  79. }
  80.  
  81.  
  82.  
  83.  
  84. /*!*/
  85. void
  86. SPH_text (point origin, char *string)
  87. {
  88.    SPH_check_system_state;
  89.    SPH_check_open_structure;
  90.  
  91.    MAKE_BABY_ELEMENT;
  92.    baby->type = ELTYP__TEXT;
  93.    baby->info.textstring = MAKE_COPY_OF_STRING (string);
  94.    bcopy (origin, baby->data.point, sizeof(point));
  95.    baby->data.point[3] = 1.0;   /* h-coordinate */
  96.    INSERT_BABY;
  97. }
  98.  
  99.  
  100.  
  101. static void
  102. StorePointList (element *baby, int vCount, point *verts)
  103. {
  104.    register i;
  105.  
  106.    baby->info.count = vCount;
  107.    ALLOC (baby->data.points, MAT3hvec, vCount, 0);
  108.  
  109.    /* COPY VERTICES, TRANSFORMING TO HVERTS. */
  110.    for (i=0; i<vCount; i++)
  111.       MAT3_SET_HVEC (baby->data.points[i] ,
  112.              verts[i][0], verts[i][1], verts[i][2], 1.0);
  113. }
  114.  
  115.  
  116.  
  117. /*!*/
  118. void
  119. SPH_polyLine (int vCount, point *verts)
  120. {
  121.    SPH_check_system_state;
  122.    SPH_check_open_structure;
  123.  
  124.    MAKE_BABY_ELEMENT;
  125.    baby->type = ELTYP__POLYLINE;
  126.    StorePointList (baby, vCount, verts);
  127.    INSERT_BABY;
  128. }
  129.  
  130.  
  131.  
  132. /*!*/
  133. void
  134. SPH_polyMarker (int vCount, point *verts)
  135. {
  136.    SPH_check_system_state;
  137.    SPH_check_open_structure;
  138.  
  139.    MAKE_BABY_ELEMENT;
  140.    baby->type = ELTYP__POLYMARKER;
  141.    StorePointList (baby, vCount, verts);
  142.    INSERT_BABY;
  143. }
  144.  
  145.  
  146.  
  147. /*!*/
  148. void
  149. SPH_fillArea (int vCount, point *verts)
  150. {
  151.    SPH_check_system_state;
  152.    SPH_check_open_structure;
  153.  
  154.    MAKE_BABY_ELEMENT;
  155.    baby->type = ELTYP__FILL_AREA;
  156.    StorePointList (baby, vCount, verts);
  157.    INSERT_BABY;
  158. }
  159.  
  160.  
  161.  
  162.  
  163. static void SimpleElement (int type, int value)
  164. {
  165.    SPH_check_system_state;
  166.    SPH_check_open_structure;
  167.  
  168.    MAKE_BABY_ELEMENT;
  169.    baby->type = type;
  170.    baby->data.value = value;
  171.    INSERT_BABY;
  172. }
  173.  
  174.  
  175. /*!*/
  176. void
  177. SPH_label (int lab)
  178. {
  179.    SimpleElement (ELTYP__LABEL,lab);
  180. }
  181.  
  182.  
  183. /*!*/
  184. void
  185. SPH_setPickIdentifier (int lab)
  186. {
  187.    SimpleElement (ELTYP__PICK_ID,lab);
  188. }
  189.  
  190.  
  191. /*!*/
  192. void
  193. SPH_setInteriorColor (int value)
  194. {
  195.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  196.       value = 0;  /* white is default color index for interiors */
  197.    SimpleElement (ELTYP__SET_INTERIOR_COLOR,value);
  198. }
  199.  
  200. /*!*/
  201. void
  202. SPH_setLineColor (int value)
  203. {
  204.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  205.       value = 1;  /* black is default color index for framed objects */
  206.    SimpleElement (ELTYP__SET_LINE_COLOR,value);
  207. }
  208.  
  209. /*!*/
  210. void
  211. SPH_setLineWidthScaleFactor (double value)
  212. {
  213.    register i;
  214.    
  215.    SimpleElement 
  216.       (ELTYP__SET_LINE_WIDTH,
  217.        ((i=LINE_WIDTH_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  218. }
  219.  
  220. /*!*/
  221. void
  222. SPH_setLineStyle (int value)
  223. {
  224.    SimpleElement (ELTYP__SET_LINE_STYLE,value);
  225. }
  226.  
  227. /*!*/
  228. void
  229. SPH_setMarkerColor (int value)
  230. {
  231.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  232.       value = 1;  /* black is default color index for framed objects */
  233.    SimpleElement (ELTYP__SET_MARKER_COLOR,value);
  234. }
  235.  
  236. /*!*/
  237. void
  238. SPH_setMarkerSizeScaleFactor (double value)
  239. {
  240.    register i;
  241.    
  242.    SimpleElement 
  243.       (ELTYP__SET_MARKER_SIZE,
  244.        ((i=MARKER_SIZE_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  245. }
  246.  
  247. /*!*/
  248. void
  249. SPH_setMarkerStyle (int value)
  250. {
  251.    SimpleElement (ELTYP__SET_MARKER_STYLE,value);
  252. }
  253.  
  254. /*!*/
  255. void
  256. SPH_setEdgeColor (int value)
  257. {
  258.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  259.       value = 1;  /* black is default color index for framed objects */
  260.    SimpleElement (ELTYP__SET_EDGE_COLOR,value);
  261. }
  262.  
  263. /*!*/
  264. void
  265. SPH_setEdgeStyle (int value)
  266. {
  267.    SimpleElement (ELTYP__SET_EDGE_STYLE,value);
  268. }
  269.  
  270. /*!*/
  271. void
  272. SPH_setEdgeFlag (int value)
  273. {
  274.    SimpleElement (ELTYP__SET_EDGE_FLAG,value);
  275. }
  276.  
  277. /*!*/
  278. void
  279. SPH_setEdgeWidthScaleFactor (double value)
  280. {
  281.    register i;
  282.    
  283.    SimpleElement 
  284.       (ELTYP__SET_EDGE_WIDTH,
  285.        ((i=LINE_WIDTH_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  286. }
  287.  
  288.  
  289.  
  290.  
  291. /*!*/
  292. void
  293. SPH_setTextFont (int value)
  294. {
  295.    SimpleElement (ELTYP__SET_TEXT_FONT, value);
  296. }
  297.  
  298. /*!*/
  299. void
  300. SPH_setTextColor (int value)
  301. {
  302.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  303.       value = 1;  /* black is default color index for framed objects */
  304.    SimpleElement (ELTYP__SET_TEXT_COLOR, value);
  305. }
  306.  
  307.  
  308.  
  309.  
  310.  
  311. /** Borrows data from edit.c **/
  312. extern structure *OPENSTRUCT;
  313. extern int ID_of_open_struct;
  314.  
  315. void
  316. SPH_executeStructure (int structID)
  317. {
  318.    register int sid;
  319.  
  320.  
  321.    SPH_check_system_state;
  322.    SPH_check_open_structure;
  323.    SPH_check_structure_id;
  324.  
  325.    MAKE_BABY_ELEMENT;
  326.    baby->type = ELTYP__EXECUTE_STRUCTURE;
  327.    baby->data.value = structID;
  328.    INSERT_BABY;
  329.  
  330.    SPH__structureTable[structID].refcount++;
  331.  
  332.    /* UPDATE THE OPEN STRUCTURE'S CHILD_LIST. */
  333.    SetBit (OPENSTRUCT->child_list, structID);
  334.  
  335.    /* UPDATE VIEWS' DESCENDENT LISTS! */
  336.    VIEWOPT__newExecuteStructure (ID_of_open_struct, structID);
  337. }
  338.